package br.com.statizo.financeiro.spring.listener;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.snoghertframework.swt.resource.ResourceUtil;
import org.snoghertframework.swt.util.impl.LayoutUtil;
import org.springframework.beans.factory.annotation.Autowired;


public class MenuFilter{

	@Autowired
	private Shell shell;
	
	@Autowired
	private LayoutUtil layoutUtil;
	
	private ToolBar toolBar;

	public void doFilter() {

		
		toolBar = new ToolBar(shell, SWT.FLAT | SWT.WRAP | SWT.RIGHT);
		layoutUtil.setFormData(toolBar, 0, 0, 100, 5);
	
		ToolItem item = new ToolItem(toolBar, SWT.PUSH);
		item.setText("ATeste");
		
		Image image = new ResourceUtil().getImage("statizo.png");
		shell.setImage(image);
		shell.setText("Statízo Financeiro");
		
		
		final Menu menuBar = new Menu(shell,SWT.BAR | SWT.BORDER_SOLID);
		shell.setMenuBar(menuBar);

		/* ############### MENU ARQUIVO ################## */

		final MenuItem file = new MenuItem(menuBar, SWT.CASCADE);
		file.setText("Arquivo");
		final Menu fileMenu = new Menu(shell,SWT.DROP_DOWN);
		file.setMenu(fileMenu);

		/* ############################################### */


		/* ########### MENU ARQUIVO - ITENS ############## */


		//PDF
		final MenuItem pdfExport = new MenuItem(fileMenu, SWT.PUSH);
		pdfExport.setText("Exportar para PDF...");		
		pdfExport.addSelectionListener(new SelectionAdapter(){

			@Override
			public void widgetSelected(SelectionEvent event) {
			}

		});

		pdfExport.setEnabled(false);


		//Planilha
		final MenuItem planExport = new MenuItem(fileMenu, SWT.PUSH);
		planExport.setText("Exportar para Planilha...");		


		planExport.addSelectionListener(new SelectionAdapter(){

			@Override
			public void widgetSelected(SelectionEvent event) {


			}

		});
		planExport.setEnabled(false);



		MenuItem separator = new MenuItem(fileMenu,SWT.SEPARATOR);


		final MenuItem exit = new MenuItem(fileMenu, SWT.PUSH);
		exit.setText("Sair");
		exit.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent evt) {

//				MessageBox msg = new MessageBox(shell, SWT.OK | SWT.CANCEL);
//				msg.setText("Sair");
//				msg.setMessage("Deseja realmente sair?");
//				int ok = msg.open();
//				if(ok == SWT.OK)
//					shell.dispose();
			}
		});

		/* ############################################### */




		/* ########### MENU CONFIG ############## */

		final MenuItem config = new MenuItem(menuBar, SWT.CASCADE);
		config.setText("Configuração");
		final Menu configMenu = new Menu(shell, SWT.DROP_DOWN);
		config.setMenu(configMenu);

		/* ############################################### */


		/* ########### MENU CONFIG - ITENS ############## */

		final MenuItem configAdd = new MenuItem(configMenu, SWT.CASCADE);
		configAdd.setText("Cadastrar");
		final Menu configAddMenu = new Menu(shell,SWT.DROP_DOWN);
		configAdd.setMenu(configAddMenu);

		//CC
		final MenuItem cc = new MenuItem(configAddMenu, SWT.PUSH);
		cc.setText("Contas-Corrente");

		cc.addSelectionListener(new SelectionAdapter() {

			@Override
			public void widgetSelected(SelectionEvent evt) {

//				ContaTransferenciaComposite contaTransferenciaComposite = (ContaTransferenciaComposite) context.getBean("contaTransferenciaComposite");
//				contaTransferenciaComposite.getController().createNew();
//				modalUtil.openDialog(contaTransferenciaComposite, AbstractEditComposite.EDIT_MODE);
//				contaTransferenciaComposite.pack();

			}

		});		


		//Tipo Lançamento
		final MenuItem tpLanc = new MenuItem(configAddMenu, SWT.PUSH);
		tpLanc.setText("Tipos de Lançamento");
		tpLanc.addSelectionListener(new SelectionAdapter() {

			@Override
			public void widgetSelected(SelectionEvent evt) {

//				modalUtil.openDialog((AbstractEditComposite<?>)context.getBean("tipoLancamentoComposite"));

			}

		});


		/*************/
		final MenuItem tpPg  = new MenuItem(configAddMenu, SWT.PUSH);
		tpPg.setText("Tipos de Pagamento");
		tpPg.addSelectionListener(new SelectionAdapter() {

			@Override
			public void widgetSelected(SelectionEvent evt) {
				//modalUtil.openDialog((AbstractEditComposite<?>)context.getBean("tipoPagamentoComposite"));
			}

		});




		final MenuItem prefs = new MenuItem(configMenu, SWT.PUSH);
		prefs.setText("Preferências");
		prefs.addSelectionListener(new SelectionAdapter() {

			@Override
			public void widgetSelected(SelectionEvent e) {

			}


		});

		/* ############################################### */
		

		
		
		/* ########### MENU HELP ############## */

		final MenuItem help = new MenuItem(menuBar, SWT.CASCADE);
		help.setText("Ajuda (?)");
		final Menu helpMenu = new Menu(shell, SWT.DROP_DOWN);
		help.setMenu(helpMenu);
		
		final MenuItem helpItens = new MenuItem(helpMenu, SWT.PUSH);
		helpItens.setText("Itens da Ajuda");
		helpItens.setEnabled(false);

		final MenuItem about = new MenuItem(helpMenu, SWT.PUSH);
		about.setText("Sobre");
		about.setEnabled(false);
		
	}

}